import { UserState, UserActionTypes, LOGIN_SUCCESS, LOGOUT } from "./types";

// user initial state
const initialState: UserState = {
    isLogin: false,
    token: "",
    profile: {
        uid: "",
        nickname: "",
        roles: [],
    },
    acls: [],
};

// user reducer
export default (state = initialState, action: UserActionTypes): UserState => {
    switch (action.type) {
        case LOGIN_SUCCESS:
            return { ...state, ...action.payload, isLogin: true };
        case LOGOUT:
            return { ...initialState };
        default:
            return state;
    }
};
